package com.LeetCode;

public class 快排的实现
{
    public static void main(String[] args)
    {
        int a[] = new int[]{1, 4, 3, 2, 8, 9, 10, 5, 6, 7};
        quickSort(a, 0, a.length - 1);
        for (int i = 0; i < a.length; i++)
        {
            System.out.println(a[i]);
        }
    }

    public static void quickSort(int arr[], int start, int end)
    {
        if (start < end)
        {
            int low = start;
            int high = end;
            int stard = arr[start];
            while (low < high)
            {
                while (low < high && arr[high] > stard) high--;
                arr[low] = arr[high];
                while (low < high && arr[low] < stard) low++;
                arr[high] = arr[low];
            }
            arr[low] = stard;
            quickSort(arr, start, low);
            quickSort(arr, low + 1, end);
        }
    }
}
